<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue讲解</title>
<link href="./css/base.css" rel="stylesheet" type="text/css"/>
<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
</head>
<body>
<div>
    <div class="hd1">参考</div>
    <a href="https://zhuanlan.zhihu.com/p/465920046" target="_blank">Vue 事件处理</a>
</div>


<div id="first">
    <h1>监控属性</h1>
    <input type="button" class="button" v-model="a" @click="add" ></input>

    <h1>监控属性 无deep</h1>
    <input type="button" class="button" @click="addB" v-model="b.b1.b2"></input>

    <h1>监控属性 有deep</h1>
    <input type="button" class="button" @click="adddeepB" v-model="deepb.b1.b2"></input>

</div>

<script type="text/javascript">
    new Vue({
        el:'#first',
        data:{
            a:1,
            b:{b1:{b2:1}},
            deepb:{b1:{b2:1}}
        },
        watch:{
            a:{
                handler(nval,oldval){
                    console.log('改变前:',oldval)
                    console.log('改变后:',nval)
                }
            },
            b:{
                handler(nval,oldval){
                    console.log('改变前:',oldval)
                    console.log('改变后:',nval)
                }
            },
            deepb:{
                handler(nval,oldval){
                    console.log('改变前:',oldval)
                    console.log('改变后:',nval)
                },
                deep:true
            }
        },
        methods:{
            add(){
                this.a++
            },
            addB(){
                this.b.b1.b2++
            },
            adddeepB(){
                this.deepb.b1.b2++
            }
            
        }
    })
</script>
</body>
</html>